﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace EADCA3MVCApp.Models
{
    public class ExistingServer
    {
        // auto implemented properties
        [Required(ErrorMessage = "You must enter the cost of your Server")]
        [Range(100, 100000, ErrorMessage="Server cost must be greater than €99.99")]
        [Display(Name = "Cost of your Existing or New Server")]
        public double ServerCost { get; set; }

        [Required]
        [Display(Name = "Cost of maintainance per Month")]
        [Range(0, 100000, ErrorMessage = "Maintanance Costs cannot be negative")]
        public double MaintainanceCost { get; set; }

        [Required]
        [Display(Name = "Cost of Software Licences per Month")]
        [Range(0, 100000, ErrorMessage = "Software Licence Costs cannot be negative")]
        public double SoftwareLicenceCost { get; set; }

        [Required]
        [Display(Name = "Number of Servers")]
        [Range(1, 100000, ErrorMessage = "You must have at least 1 Server")]
        public int NoOfServers { get; set; }

        // monthly cost field
        double monthlyCost;

        // years of useful life of physical server
        int yearsOfUse = 3;

        // calculate monthly cost of existing server
        [Display(Name = "Monthly Cost of your physical Server")]
        public double MonthlyCost
        {
            get
            {
                double server = ServerCost / yearsOfUse / 12;
                monthlyCost = Math.Round((server + MaintainanceCost + SoftwareLicenceCost) * NoOfServers, 2);
                return monthlyCost;
            }
        }

        // instance size corelates with price of server
        string instanceSizeRequired;

        // set the cost/instance size relationship
        double vSmall = 750.00;
        double small = 1000.00;
        double medium = 1500.00;
        double large = 2000.00;

        public string InstanceSizeRequired
        {
            get
            {
                if (ServerCost <= vSmall)
                {
                    instanceSizeRequired = "Very Small";
                }
                else if ((ServerCost > vSmall) && (ServerCost <= small))
                {
                    instanceSizeRequired = "Small";
                }
                else if ((ServerCost > small) && (ServerCost <= medium))
                {
                    instanceSizeRequired = "Medium";
                }
                else if ((ServerCost > medium) && (ServerCost <= large))
                {
                    instanceSizeRequired = "Large";
                }
                else
                {
                    instanceSizeRequired = "Very Large";
                }
                return instanceSizeRequired;
            }
        }
    }
}